CONTENTS | INDEX | PREV | NEXT
 _main

 NAME
  _main - main program entry, bypass standard c.lib initialization

 SYNOPSIS
  void _main(int arglen, char *argptr)
  {
      /* your main routine goes here */
  }

 FUNCTION
  The _main() entry point is called by the startup module (c.o).
  Normally _main() is part of c.lib and does stdio and other
  initialization before calling the user main() routine.  _main()
  is responsible for openning the stderr channel as well.

  However, if you specify your own _main() you will overide the
  c.lib version.  Normally you either fall through or _exit() from
  _main.

  A programmable can use the _main entry point when the executable
  uses nothing but system library routines.  That is, you make no
  calls to stdio functions such as puts(), printf(), etc..., to low
  level IO routines such as open(), close(), read(), etc..., or
  malloc() or any routine that uses malloc().

  Self contained routines such as strcpy() may still be called, and, of
  course, you may open any libraries you wish and make library calls.

  Since the auto-library openning and closing is done by the startup
  module (c.o), "dos.library" will still be openned for you
  automatically if you make any DOS calls.

  Using the _main entry point usually results in a substantially
  smaller executable because stdio and other library routines
  referenced by the c.lib _main() and exit() are never referenced
  and thus never become part of the executable.  It is NOT SUGGESTED
  that beginning C programmers use the _main() entry point.

 NOTE
  _main is called by the startup module whether the program was run
  from the CLI or the WORKBENCH.  You must detect which yourself and
  also deal with the workbench message yourself.

 EXAMPLE
  /*
   *  This program comes to approximately a 552 byte executable
   */

  _main()
  {
      Write(Output(), "UG!n", 4);
      _exit(1);
  }

 SEE ALSO
  _exit, main, exit